import Cookies from 'js-cookie'

const app = {
  state: {
    sidebar: {
      isCollapse: Cookies.get('sidebarIsCollapse') === 1
    }
  },
  mutations: {
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.isCollapse) {
        Cookies.set('sidebarIsCollapse', 0)
      } else {
        Cookies.set('sidebarIsCollapse', 1)
      }
      state.sidebar.isCollapse = !state.sidebar.isCollapse
    }
  },
  actions: {
    ToggleSideBar({ commit }) {
      commit('TOGGLE_SIDEBAR')
    }
  }
}

export default app
